﻿using System;
using System.Collections.Generic;
using System.Text;


namespace FireBus.Shell.ExtensionManager
{
	public class ListCommand : ICommand
	{
		private readonly Extension _Extension;


		public ListCommand(Extension extension)
		{
			if (extension == null)
			{
				throw new ArgumentNullException("extension");
			}
			_Extension = extension;
		}

		public String Name
		{
			get { return "list"; }
		}

		public String Description
		{
			get { return "Prints out all host extensions. No arguments needed."; }
		}

		public String Execute(IList<String> args)
		{
			var stringBuilder = new StringBuilder();
			stringBuilder.Append("Extension list:");
			const String template = "\n{0,-40} | {1,10}";
			stringBuilder.AppendFormat(
				template, "Name", "State");
			var extensions = _Extension.GetExtensions();
			foreach (var extension in extensions)
			{
				stringBuilder.AppendFormat(
					template, extension.Name, _Extension.GetExtensionState(extension.Name));
			}

			return stringBuilder.ToString();
		}
	}
}
